package com.yzt;

public class ArrayMax {
    public static void main(String[] args) {
        int[] arr1 = {1,8,3,4};
        int maxValue = arr1[0];
        for (int i = 1; i < arr1.length; i++) {
            if (maxValue < arr1[i]) {
                maxValue = arr1[i];
            }
        }
        System.out.println(maxValue);

        // 寻找
        // 第一种简便方法
//        int[] arr2 = {5,8,5,8};
//        int a = -1;
//        int num = 9;
//        for (int i = 0; i < arr2.length; i++) {
//            if (num == arr2[i]) {
//                a = i;
//                break;
//            }
//        }
//        System.out.println("这个数出现的位置下标是 :" + a);

        // 第二种常规方法
/*
        boolean flag = true;
        int[] arr3 = {2,3,5,5,9};
        int firstNum = 7;
        for (int i = 0; i < arr3.length; i++) {
            if (firstNum == arr3[i]) {
                flag = true;
                System.out.println("这个数的数组下标为" + i);
                break;
            }
            flag = false;
        }
        if (flag == false) {
            System.out.println(-1);
        }
*/
        int[] arr3 = {2,3,5,5,9};
        // 数组中的值前后对调
        for (int i = 0; i < arr3.length/2; i++) {
            int a = arr3[i];
            arr3[i] = arr3[arr3.length - 1 -i];
            arr3[arr3.length - 1 - i] = a;
        }
        for (int i = 0; i < arr3.length; i++) {
            System.out.print(arr3[i] + ",");
        }
        System.out.println("-------");
        for (int value : arr3) {
            System.out.print(value + ",");

        }





    }
}
